package com.yx.front.config;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author YangXiong
 */
@Api(value = "/api", tags = "swagger示例接口")
@RestController
@RequestMapping(value = "/api", produces = {"application/json"})
@EnableSwagger2
/*
 * http://localhost:9000/swagger-ui.html
 */

public class SwaggerConfig {
    @Value("${swagger.enable:false}")
    private boolean enable;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                /*
                 * api的配置路径
                 */
                .apis(RequestHandlerSelectors.any())
                /*
                 * 扫描路径选择
                 */
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .enable(enable);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                /*
                 * 文档标题
                 */
                .title("在线阅览室系统")
                /*
                 *接口概述
                 */
                .description("在线阅览室接口文档")
                /*
                 *版本号
                 */
                .version("1.0")
                /*
                 *服务的域名
                 */
                .termsOfServiceUrl("url")
                .build();
    }
}